package springboot.houbank.com.web;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springboot.houbank.com.AsyncCall.TaskAsync;
import springboot.houbank.com.domain.User;
import springboot.houbank.com.service.PersonService;
import springboot.houbank.com.service.UserService;

import java.util.List;

/**
 * Created by zhaoqiguo on 2016/8/23.
 */
@RestController
public class HelloController {
    Logger logger = LoggerFactory.getLogger(HelloController.class);
    @Autowired
    private UserService userService;
    @Autowired
    private PersonService personService;
    @Autowired
    private TaskAsync taskAsync;

    @ApiOperation(value = "测试",notes = "")
    @RequestMapping(value = "/hello" ,method = RequestMethod.GET)
    public String index() throws Exception{
     // List<User> list = userMapper.queryAll();
       /* logger.info("hello test ---start");
        logger.debug("dubug --- test ---");
        User user = new User();
        user.setAge(12);
        user.setUsername("lisi");
        taskAsync.doTaskOne();
        taskAsync.doTaskTwo();
        userService.insertUser(user);
        logger.info("hello test ---end");*/

        //userService.insertData();
        return "Hello World";
    }

    @ApiOperation(value = "查询所有用户信息",notes = "")
    @RequestMapping(value = "/queryAll",method = RequestMethod.GET)
    public String queryAll(){
     List<User> list =  userService.queryAll();
        return "ok";
    }

    @ApiOperation(value = "添加用户" , notes = "根据用户对象创建对象")
    @ApiImplicitParam(name = "user", value = "用户详细实体user", required = true,dataType = "User")
    @RequestMapping(value = "/insertData",method = RequestMethod.POST)
    public String insertData(@RequestBody User user){
        userService.insertData();
        logger.debug("dubug --- insertData ---");
        return "ok";
    }


    @ApiOperation(value = "更新用户信息",notes ="根据用户id来指定更新的用户，并根据传递过来的user来更新用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户id", required = true, dataType = "String",paramType = "path"),
            @ApiImplicitParam(name = "user", value = "用户详细实体User", required = true, dataType = "User")
    })
    @RequestMapping(value = "updateUser",method = RequestMethod.POST)
    public String updateUser(String id, @RequestBody User user){
        logger.debug("dubug --- updateUser ---");
        return "ok";
    }

    @ApiOperation(value = "删除用户信息",notes = "根据url的id来指定删除对象")
    @ApiImplicitParam(name = "id",value = "用户id",required = true,dataType = "Long",paramType = "path")
    @RequestMapping(value = "/{id}",method = RequestMethod.POST)
    public String delete(@PathVariable Long id){

        return "ok";
    }
}
